/*
 * @Description:
 * @Author: dh
 * @Date: 2021-09-24 16:49:14
 * @LastEditors: dh
 * @LastEditTime: 2022-11-22 16:00:08
 */

//TODO keyof 用于获取某种类型的所有键，其返回类型是联合类型
interface keyofType {
	id: number
	name: string
	age?: number
}

type B1 = keyof keyofType //  "id" | "name" | "age"
const b10: B1 = 'name'

console.log('==========================================================')

const person = {
	age: 3,
	text: 'hello world',
}

// 这样无法获取返回类型
// function get1(o: object, name: string) {
//     return o[name];
// }
function get1<T extends object, K extends keyof T>(o: T, name: K): T[K] {
	return o[name]
}

const age1 = get1(person, 'age')
const text1 = get1(person, 'text')

//TODO in 用来遍历枚举类型
type Keys = 'aaa' | 'bbbb'
type Obj = {
	[key in Keys]: number
}
const obj: Obj = { aaa: 1, bbbb: 2 }

// TODO keyof any
type a = keyof any // string | number | symbol
